﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufBase.h"
#include <queue>
#include "GnufQtObjectPtr.h"

namespace gnuf 
{
    class Pallet;
    class Info;
    class QtFall;
    class Bulletin;
    class QtFall;
    class AutoRaiser;

    class GNUF_BASE_EXPORT Fall final : public gcmp::WeakReferenceable
    {
    public:
        enum class DirectionFrom { Left, Center, Right };

    public:
        Fall(gcmp::OwnerPtr<QtFall>&& qtItem);
        ~Fall();

    public:
        void push(gcmp::OwnerPtr<Bulletin>&&, int milliSecond = 500);
        void pop();
        void pop(const Bulletin*);

        void popImmediately();
        void popImmediately(const Bulletin* bulletin);

        void resume();

        void stopTimer();
        void restartTimer();

        size_t size() { return m_queue.size(); }

        void setDuration(int milliSecond) { m_duration = milliSecond; }
        int duration() const { return m_duration; }

        void setInterval(int milliSecond) { m_interval = milliSecond; }
        int interval() const { return m_interval; }

        void setPos(int x, int y) { m_x = x; m_y = y; }
        int posX() const { return m_x; }
        int posY() const { return m_y; }

        void setSpacing(int spacing) { m_spacing = spacing; }
        int spacing() const { return m_spacing; }

        void setDirectionFrom(DirectionFrom dir) { m_from = dir; }
        DirectionFrom directionFrom() const { return m_from; }

        bool isExistSameBulletin(const std::wstring& text);

        // 置顶提示窗体
        void raise() const;

        // 是否还有展示中的提示
        bool isEmpty() const;

    private:
        // 启动置顶提示窗体的异步事件，
        void startRaiser();

        // 结束置顶提示窗体的异步事件
        void exitRaiser() ;

    private:
        int m_duration = 3000, m_interval = 500;
        gcmp::QtAutoPtr<QtFall> m_qtItem = nullptr;
        std::list<const Pallet*> m_queue;

        std::list<gcmp::OwnerPtr<Bulletin>> m_queueBulletin;
        int m_x = 0, m_y = 0;
        int m_spacing = 6;
        DirectionFrom m_from = DirectionFrom::Center;
        gcmp::WeakPtr<AutoRaiser> m_wpRaiser;
    };
}
